package com.zone.domain.acticity.repository;

import com.zone.domain.acticity.model.aggregate.CreateActivityOrderAggregate;
import com.zone.domain.acticity.model.aggregate.PartakeActivityOrderAggregate;
import com.zone.domain.acticity.model.entity.*;
import com.zone.domain.acticity.model.valobj.ActivitySkuStockSubTaskVO;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author: zongzi
 * @description: 活动相关
 * @date: 2024/6/30
 */
@Repository
public interface IActivityRepository {

    /**
     * 查询活动库存
     *
     * @param sku 库存唯一标识
     * @return 库存
     */
    ActivitySkuEntity queryActivitySku(Long sku);

    /**
     * 查询活动信息
     *
     * @param activityId 活动id
     * @return 活动信息
     */
    ActivityEntity queryActivity(Long activityId);

    /**
     * 查询活动次数配置信息
     *
     * @param activityCountId 活动次数配置id
     * @return 活动次数配置
     */
    ActivityCountEntity queryActivityCount(Long activityCountId);

    /**
     * 创建活动订单
     *
     * @param createActivityOrderAggregate 订单聚合对象
     */
    ActivityOrderEntity createNoPayActivityOrder(CreateActivityOrderAggregate createActivityOrderAggregate);

    /**
     * 创建活动订单（需要支付的）
     *
     * @param createActivityOrderAggregate 订单聚合对象
     */
    ActivityOrderEntity createPayActivityOrder(CreateActivityOrderAggregate createActivityOrderAggregate);

    /**
     * 装配sku库存数量到缓存
     *
     * @param sku
     * @param stockCount 库存数量
     */
    void assembleSkuStock(Long sku, Integer stockCount);

    /**
     * 扣减活动库存（渐减式扣减 100，99，98...）
     *
     * @param sku
     */
    boolean descActivitySkuStock(Long sku);

    /**
     * 活动sku扣减任务加入队列
     *
     * @param subTaskVO
     */
    void offerActivitySkuStockSubTask(ActivitySkuStockSubTaskVO subTaskVO);

    /**
     * 获取活动sku扣减任务
     *
     * @return
     */
    ActivitySkuStockSubTaskVO pollAwardStockSubTask();

    /**
     * 扣减活动库存剩余数量 - 1
     *
     * @param sku
     */
    void decrActivitySkuCountSurplus(Long sku);

    void clearZeroActivitySkuCount(Long sku);

    /**
     * 创建用户参与活动单（新增用户参与活动单、扣减用户活动次数账户）
     *
     * @param aggregate 聚合对象
     */
    void createUserRaffleOrder(PartakeActivityOrderAggregate aggregate);

    /**
     * 查询用户参与抽奖单
     *
     * @param userId     用户id
     * @param activityId 活动id
     * @param orderState 订单状态
     * @return
     */
    UserRaffleOrderEntity queryUserRaffleOrder(String userId, Long activityId, String orderState);

    RaffleActivityAccountEntity queryActivityAccount(String userId, Long activityId);

    RaffleActivityAccountMonthEntity queryActivityAccountMonth(String userId, Long activityId, String month);

    RaffleActivityAccountDayEntity queryActivityAccountDay(String userId, Long activityId, String day);

    List<ActivitySkuEntity> queryActivitySkuList(Long activityId);

    Integer queryUserDayRaffleCount(String userId, Long strategyId);

    Integer queryUserDayRaffleCountByActivityId(String userId, Long activityId);

    RaffleActivityAccountEntity queryUserActivityAccount(String userId, Long activityId);

    ActivityOrderEntity queryActivityOrderByOutBusinessNo(String outBusinessNo);

    void rechargeAccountByOrder(ActivityOrderEntity activityOrderEntity);

    List<SkuProductEntity> querySkuProductList(Long activityId);

    /**
     * 查询最近一个月未支付的活动流水单（取一条）
     *
     * @param userId 用户id
     * @param sku    下单的sku
     * @return 未支付的活动流水单
     */
    ActivityOrderEntity queryRecentOneMonthNoPayOrder(String userId, Long sku);
}
